package studentinformationmanagementsystem.dao.impl;

import studentinformationmanagementsystem.dao.BaseDao;
import studentinformationmanagementsystem.dao.GradeTableDao;
import studentinformationmanagementsystem.entity.GradeTable;

import java.util.List;

/**
 * @author 苗庆
 * @version 1.0
 */
public class GradeTableDaoImpl extends BaseDao implements GradeTableDao {



    /**
     * 对成绩表信息进行添加
     * @param gradeTable  成绩表对象
     * @return  受影响的记录行数
     */
    @Override
    public int insert(GradeTable gradeTable) {
        String sql="INSERT INTO `t_gradeTable`(`studid`,`courseid`,`teacherid`,`finalGrade`,`usualPerformance`,`creditHour`,`finalScore`,`IsDelete`)VALUES(?,?,?,?,?,?,?,?)";
        return super.update(sql,gradeTable.getStudid(),gradeTable.getCourseid(),gradeTable.getTeacherid(),gradeTable.getFinalGrade(),gradeTable.getUsualPerformance(),gradeTable.getCreditHour(),gradeTable.getFinalScore(),gradeTable.getIsDelete());
    }


    /**
     *  根据ID更新成绩表信息
     * @param gradeTable  成绩表对象
     * @return 受影响的记录行数
     */
    @Override
    public int update(GradeTable gradeTable) {
        String sql="UPDATE `t_gradeTable` SET `studid`=?,`courseid`=?,`teacherid`=?,`finalGrade` = ? ,`usualPerformance` = ? ,`creditHour` = ? ,`finalScore` = ? ,`IsDelete` = ? WHERE `gradeTableId` =?";
        return super.update(sql,gradeTable.getStudid(),gradeTable.getCourseid(),gradeTable.getTeacherid(),gradeTable.getFinalGrade(),gradeTable.getUsualPerformance(),gradeTable.getCreditHour(),gradeTable.getFinalScore(),gradeTable.getIsDelete(),gradeTable.getGradeTableId());    }


    /**
     *  根据ID删除成绩表
     * @param gradeTable 成绩表ID
     * @return 受影响的记录行数
     */
    @Override
    public int delete(GradeTable gradeTable) {
        String sql="DELETE FROM `t_gradeTable` WHERE `gradeTableId`=? AND `IsDelete`=0";
        return super.update(sql,gradeTable.getGradeTableId());
    }


    /**
     * 查询所有成绩表信息
     * @return 所有成绩表信息
     */
    @Override
    public List<GradeTable> queryAll() {
        String sql="SELECT * FROM `t_gradeTable` WHERE `IsDelete`=0";
        return super.queryForList(GradeTable.class,sql);
    }


    /**
     * 根据成绩表ID查询成绩表信息
     * @param gradeTable 成绩表ID
     * @return 成绩表信息
     */
    @Override
    public GradeTable queryById(GradeTable gradeTable) {
        String sql = "SELECT * FROM `t_gradeTable` WHERE `gradeTableId` = ? AND `IsDelete`=0";
        return super.queryForOne(GradeTable.class, sql, gradeTable.getGradeTableId());
    }


    /**
     * 根据课程id和学生id号查询成绩表信息   不用考虑是否删除
     * @param gradeTable 成绩表ID
     * @return 成绩表信息
     */
    @Override
    public GradeTable queryById01(GradeTable gradeTable) {
        String sql="SELECT * FROM `t_gradeTable` WHERE  `courseid` = ? AND `studid` = ?";
        return super.queryForOne(GradeTable.class,sql,gradeTable.getCourseid(),gradeTable.getStudid());
    }

    /**
     * 查询总记录条数
     */
    @Override
    public Integer queryForPageTotalCount() {
        String sql = "SELECT COUNT(1) FROM `t_gradeTable` WHERE `IsDelete`=0 ";
        Number count = (Number) queryForSingleValue(sql);
        return count.intValue();
    }

    /**
     * 分页查询DAO层方法
     *
     * @param begin    起始记录行数
     * @param pageSize 每页展示数量
     * @return
     */
    @Override
    public List<GradeTable> queryForPageItems(int begin, int pageSize) {
        String sql = "SELECT * FROM `t_gradeTable` WHERE `IsDelete`=0 LIMIT ?, ?";
        return super.queryForList(GradeTable.class, sql, begin, pageSize);
    }
}
